package com.ruoyi.business.controller;

import com.ruoyi.business.domain.FileLoanApplication;
import com.ruoyi.business.domain.vo.FileLoanApplicationVo;
import com.ruoyi.business.service.IFileLoanApplicationService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 借阅申请Controller
 *
 * @author sal
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/business/fileLoanApplication")
public class FileLoanApplicationController extends BaseController {
    @Autowired
    private IFileLoanApplicationService fileLoanApplicationService;

    /**
     * 查询借阅申请列表
     */
    @PreAuthorize("@ss.hasPermi('business:fileLoanApplication:list')")
    @GetMapping("/list")
    public TableDataInfo list(FileLoanApplicationVo fileLoanApplicationVo, PageQuery pageQuery) {
        return fileLoanApplicationService.selectPageFileLoanApplicationList(fileLoanApplicationVo, pageQuery);
//        startPage();
//        List<FileLoanApplication> list = fileLoanApplicationService.selectFileLoanApplicationList(fileLoanApplication);
//        return getDataTable(list);
    }

    /**
     * 导出借阅申请列表
     */
    @PreAuthorize("@ss.hasPermi('business:fileLoanApplication:export')")
    @Log(title = "借阅申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(FileLoanApplication fileLoanApplication, HttpServletResponse response) {
        List<FileLoanApplication> list = fileLoanApplicationService.selectFileLoanApplicationList(fileLoanApplication);
        ExcelUtil.exportExcel(list, "借阅申请", FileLoanApplication.class, response);
//        ExcelUtil<FileLoanApplication> util = new ExcelUtil<FileLoanApplication>(FileLoanApplication.class);
//        return util.exportExcel(list, "fileLoanApplication");
    }

    /**
     * 获取借阅申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:fileLoanApplication:query')")
    @GetMapping(value = "/{id}")
    public R<FileLoanApplication> getInfo(@PathVariable("id") Long id) {
        return R.ok(fileLoanApplicationService.selectFileLoanApplicationById(id));
    }

    /**
     * 新增借阅申请
     */
    @PreAuthorize("@ss.hasPermi('business:fileLoanApplication:add')")
    @Log(title = "借阅申请", businessType = BusinessType.INSERT)
    @PostMapping
    public R<FileLoanApplication> add(@RequestBody FileLoanApplication fileLoanApplication) {
        return R.ok(fileLoanApplicationService.insertFileLoanApplication(fileLoanApplication));
    }

    /**
     * 修改借阅申请
     */
    @PreAuthorize("@ss.hasPermi('business:fileLoanApplication:edit')")
    @Log(title = "借阅申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<FileLoanApplication> edit(@RequestBody FileLoanApplication fileLoanApplication) {
        return R.ok(fileLoanApplicationService.updateFileLoanApplication(fileLoanApplication));
    }

    /**
     * 删除借阅申请
     */
    @PreAuthorize("@ss.hasPermi('business:fileLoanApplication:remove')")
    @Log(title = "借阅申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@PathVariable List<Long> ids) {
        return toAjax(fileLoanApplicationService.deleteFileLoanApplicationByIds(ids));
    }
}
